package com.qianzhou.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 * @Author: qian.zhou
 * @Description: SwaggerConfig配置信息
 * @Date Created in 2021-08-31-16:25
 * @Modified By:
 */
@Configuration
@EnableSwagger2
@ComponentScan(basePackages = {"com.qianzhou.eduWeb.controller"})
public class SwaggerConfig {
    @Bean
    public Docket createRestApiUser() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("用户模块")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/user/**"))
                .build();
    }

    @Bean
    public Docket createRestApiCourseComment() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("课程评论模块")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/course/comment/**"))
                .build();
    }

    @Bean
    public Docket createRestApiCourse() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("课程模块")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/course/**"))
                .build();
    }

    @Bean
    public Docket createRestApiCourseOrder() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("课程订单模块")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/order/**"))
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("教育信息管理项目-主业务模块API")
                .description("教育信息管理项目-主业务模块API-描述信息")
                .termsOfServiceUrl("http://localhost:8002/swagger-ui.html")
                .contact(new Contact("qian.zhou", "https://gitee.com/zhou-andreas", "1292184670@qq.com"))
                .version("1.1.0")
                .build();
    }
}